home *** CD-ROM | disk | FTP | other *** search
/ SoundMaker 2003 (Professional Edition) / SoundMaker 2003 - Professional Edition.iso / midi tool / midioxse.exe / DATA.1 / Polychord.vbs < prev    next >
Text File  |  1999-11-26  |  3KB  |  128 lines

  1. ' MIDIOX Test
  2. ' Copyright (c) 2000 by Jamie O'Connell
  3. '
  4. ' This script is an example of doing VBScript with MIDI-OX
  5. ' It puts each successive held note on a different MIDI channel
  6. option explicit
  7.  
  8. dim mox
  9. dim str, strWrk, strSysEx
  10. dim n, ii, nInst
  11. dim bGo, bFound
  12. dim notesOn
  13. dim baseChan
  14. dim aryOn(10)
  15.  
  16. ' Create object
  17. Set mox = WScript.CreateObject("MoxKart.MoxWire.1", "On_")  
  18.  
  19. n = mox.NumberInstances
  20. If n > 0 Then
  21.    nInst = 1
  22.    If n > 1 Then
  23.       nInst = InputBox( "Attach to which instance? (1 to " & n & ")", "Attach", "1" )
  24.    End If
  25.    If mox.AttachInstance( nInst ) = 1 Then     
  26.       MsgBox "Attached Instance: " & nInst
  27.    Else
  28.       MsgBox "Could not Attach Instance: " & nInst
  29.    End If
  30. ElseIf mox.LaunchInstance = 1 Then
  31.    nInst = 1
  32.    If mox.AttachInstance( nInst ) = 1 Then    
  33.       MsgBox "Launched and Attached Instance: " & nInst
  34.    Else
  35.       MsgBox "Launched but could not Attach Instance: " & nInst   
  36.    End If
  37. Else
  38.    MsgBox "Launch MIDI-OX Failed"
  39. End If
  40.  
  41. n = mox.NumberInstances
  42.  
  43. For ii = 0 to 9
  44.   aryOn(ii) = -1
  45. Next
  46.  
  47. ' *** Try out our MIDI Input loop
  48. notesOn  = 0         ' init
  49. baseChan = 0      ' init -- we expect channel 1
  50. If mox.IsAttached = 1 then
  51.    mox.DivertMidiInput = 1
  52.    mox.FireMidiInput = 1
  53.    
  54.    MsgBox "Press OK to end PolyChord MIDI Loop"
  55.    
  56.    mox.FireMidiInput = 0
  57.    mox.DivertMidiInput = 0
  58. End If
  59.  
  60. Set str    = nothing
  61. Set strWrk = nothing
  62. Set mox    = nothing
  63.  
  64. ' Exit Point
  65. '------------------------------------------
  66.  
  67. Sub On_MidiInput( ts, stat, chan, dat1, dat2)
  68.    dim newStat, newChan
  69.  
  70.    newChan = chan
  71.  
  72.    If chan = baseChan Then
  73.       If stat = &h90 And dat2 > 0 Then    ' Note On
  74.          If aryOn( notesOn ) = -1 Then    ' Use this One
  75.         aryOn( notesOn ) = dat1
  76.             newChan = notesOn           
  77.          Else
  78.             bFound = false
  79.         For ii = 0 to 10
  80.            If aryOn( ii ) = -1 Then
  81.               aryOn( ii ) = dat1
  82.                   newChan = ii
  83.                   bFound = true
  84.           Exit For
  85.                End If
  86.             Next
  87.      
  88.             If bFound = false then
  89.                aryOn( notesOn ) = dat1
  90.                newChan = notesOn           
  91.         End If 
  92.          End If
  93.          notesOn = notesOn + 1 ' the next note on will be on the next channel
  94.       ElseIf (stat = &h90 And dat2 = 0) Or stat = &h80 Then ' Note Off
  95.          If aryOn( notesOn ) = dat1 Then    ' Use this One
  96.         aryOn( notesOn ) = -1
  97.             newChan = notesOn           
  98.          Else
  99.         For ii = 10 to 0 step -1
  100.                If aryOn( ii ) = dat1 Then  
  101.                   aryOn( ii ) = -1
  102.                   newChan = ii
  103.                   Exit For
  104.                End If 
  105.             Next
  106.          End If
  107.          notesOn = notesOn - 1            ' next note goes on previous channel
  108.       End If
  109.       
  110.       If newChan > 15 Then        ' sanity check
  111.          newChan = 0
  112.       End If     
  113.    End If
  114.  
  115.    newStat = stat + newChan ' send out next chan 
  116.    mox.OutputMidiMsg newStat, dat1, dat2
  117.     
  118. End Sub
  119.  
  120. '------------------------------------------
  121. ' connection point sink for SysEx
  122.  
  123. Sub On_SysExInput( strSysEx )
  124.    mox.SendSysExString strSysEx    
  125. End Sub
  126.  
  127.  
  128.